import java.util.*;
import java.io.*;

public class Card implements Comparable<Card>, Serializable{
    public enum Rank{DEUCE, THREE, FOUT, FIVE, SIX, SEVEN, EIGHT, NINE, TEM, JACK, QUEEN, KING, ACE};
    public enum Suit{CLUBS, DIAMONDS, HEARTS, SPADES};
    
    private final Rank rank;
    private final Suit suit;
    
    private Card(Rank rank, Suit suit){
        if(rank == null || suit==null)
            throw new NullPointerException(rank + "," + suit);
        this.rank = rank;
        this.suit = suit;

    } 
    public Rank rank(){return rank;}
    public Suit suit(){return suit;}
    public String toString(){return rank + " of " + suit;}
    
    public int compareTo(Card c){
        int suitCompare = suit.compareTo(c.suit);
        return (suitCompare != 0 ? suitCompare : rank.compareTo(c.rank));
    }
        
    private static final List<Card> prototypeDeck = new ArrayList<Card>(52);
    static{
        for(Suit suit : Suit.values())
            for(Rank rank : Rank.values())
                prototypeDeck.add(new Card(rank, suit));
    }
    
    public static List<Card> newDeck(){
        return new ArrayList<Card>(prototypeDeck);
    }
}